home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / mAz Lite 1.0 / animate.wdl < prev    next >
Encoding:
Text File  |  2003-03-17  |  25.2 KB  |  902 lines

  1. // Template file v5.202 (02/20/02)
  2. ////////////////////////////////////////////////////////////////////////
  3. // File: animate.wdl
  4. //        WDL prefabs for model animation
  5. ////////////////////////////////////////////////////////////////////////
  6. // Use:
  7. //        Include AFTER "movment.wdl"
  8. //
  9.  
  10. DEFINE _WALKDIST,SKILL27;    // distance per walk cycle
  11. DEFINE _RUNDIST,SKILL28;    // distance per run cycle
  12.  
  13.  
  14.  
  15. //@ Animate Vars
  16. var anim_attack_ticks = 16;// time for one attack animation cycle
  17.  
  18. var anim_stand_ticks = 16;    // time for one standing anim cycle
  19. var anim_jump_ticks = 6;     // time for one jump animation cycle
  20. var anim_duck_ticks = 8;     // time for one duck animation cycle
  21.  
  22. var anim_walk_dist = 1;     // dist per model width per walk cycle
  23. var anim_run_dist = 1.5;    // dist per model width per run cycle
  24. var anim_crawl_dist = 0.8; // dist per model width per crawl cycle
  25. var anim_wade_dist = 0.8;    // dist per model width per crawl cycle
  26. var anim_swim_dist = 1;     // dist per model width per swim cycle
  27.  
  28. var walk_or_run = 12;     // max quants per tick to switch from walk to run animation
  29.  
  30.  
  31. // strings for defining the animation frames
  32. STRING anim_stand_str,"stand";
  33. STRING anim_walk_str,"walk";
  34. STRING anim_run_str,"run";
  35. STRING anim_duck_str,"duck";
  36. STRING anim_swim_str,"swim";
  37. STRING anim_dive_str,"dive";
  38. STRING anim_jump_str,"jump";
  39. STRING anim_crawl_str,"crawl";
  40. STRING anim_wade_str,"walk";
  41.  
  42. // string synonyms for defining the animation frames (and their default values)
  43. STRING anim_default_death_str,"death";
  44. STRING anim_default_attack_str,"attack";
  45. //SYNONYM anim_attack_str { TYPE STRING; DEFAULT anim_default_attack_str;}
  46. string* anim_attack_str = anim_default_attack_str;
  47. //SYNONYM anim_death_str { TYPE STRING; DEFAULT anim_default_death_str;}
  48. string* anim_death_str = anim_default_death_str;
  49.  
  50. //SYNONYM anim_str { TYPE STRING; }
  51. string* anim_str;
  52.  
  53.  
  54.  
  55. //@ Function prototypes
  56.  
  57. function anim_airborne();   // animate 'airborne' entity
  58. function anim_init();        // initialize the actor animation style
  59. function actor_anim();        // handle actor animation
  60. function    actor_anim_transition(str_anim_target);    // handle transition animation between states
  61. function actor_anim_old_style_anim();    // old animation style (for compatability)
  62.  
  63. //#ACTION drop_shadow;            // create a shadow sprite under entity (use move_shadow() to move)
  64. function move_shadow();        // move shadow sprite under entity
  65. function attach_entity();    // attach an entity with same origin/frames
  66.  
  67. //@ Function code
  68.  
  69. /////////////////////////////////////////////////////////////////////////
  70. // Desc: animate 'airborne' entity
  71. function anim_airborne()
  72. {
  73.     // standing animation
  74.     if(MY._POWER > 0)    // engine running
  75.     {
  76.         MY._ANIMDIST += TIME * MY._POWER;
  77.         // wrap animation time to a value between zero and anim_stand_ticks
  78.         if(MY._ANIMDIST > anim_stand_ticks)
  79.         {
  80.             MY._ANIMDIST -= anim_stand_ticks;
  81.         }
  82.         // calculate a percentage out of the animation time
  83.         temp =  100 * MY._ANIMDIST / anim_stand_ticks;
  84.         // set the frame from the percentage
  85.         ent_cycle(anim_stand_str,temp);
  86.         return;
  87.     }
  88.     return;
  89. }
  90.  
  91.  
  92. /////////////////////////////////////////////////////////////////////////
  93. // Desc: set up for animation
  94. //         scale entity by actor_scale
  95. //            if using the "old style animation"
  96. //              - split the integer and fractional parts of the animation
  97. //                  frame numbers, and store distance factors
  98. //
  99. function anim_init()
  100. {
  101.     vec_scale(MY.SCALE_X,actor_scale);
  102.  
  103.     if(int(MY._WALKFRAMES) < 0) { return; }    // use adv animation
  104.  
  105.     temp = frc(MY._WALKFRAMES) * 1000;
  106.     if(temp != 0)
  107.     {
  108.         // old style animation
  109.         MY._WALKFRAMES = int(MY._WALKFRAMES);
  110.         if(MY._WALKFRAMES == 0) { MY._WALKFRAMES = 13; }
  111.         MY._WALKDIST = MY._WALKFRAMES / temp;
  112.  
  113.         temp = frc(MY._RUNFRAMES) * 1000;
  114.         MY._RUNFRAMES = int(MY._RUNFRAMES);
  115.         if(MY._RUNFRAMES == 0) { MY._RUNFRAMES = 5; }
  116.         MY._RUNDIST = MY._RUNFRAMES / temp;
  117.     }
  118. }
  119.  
  120.  
  121.  
  122. ////////////////////////////////////////////////////////////////////////
  123. // Desc: *ADVANCED* actor animation function
  124. //
  125.  
  126. DEFINE _ADVANIM_TICK,SKILL1;    // 'tick' related animation
  127. DEFINE _ADVANIM_DIST,SKILL2;  // 'dist' related animation
  128.  
  129. // Define Masks
  130. DEFINE MASK_ANIM_ATTACK_TICKS,2093056;    // upper 9 (less topbit)
  131. DEFINE MASK_ANIM_JUMP_TICKS,4032;         // mid 6
  132. DEFINE MASK_ANIM_DUCK_TICKS,63;             // lower 6
  133.  
  134. DEFINE MASK_ANIM_RUN_DIST,    2064384;    // upper 6 (less topbit)
  135. DEFINE MASK_ANIM_WALK_DIST, 31744;    // next 5
  136. DEFINE MASK_ANIM_CRAWL_DIST, 992;    // next 5
  137. DEFINE MASK_ANIM_SWIM_DIST, 31;        // bottom 5
  138.  
  139.  
  140. // Desc: 'Advanced' animation function. This allows the user to set animation
  141. //        cycle distances and timing on an individual entity level.See the
  142. //        "Scriptless Shooter" tutorial for details.
  143. //
  144. function actor_adv_anim()
  145. {
  146.     // START ADVANCED STYLE ANIMATIONS (frame names)
  147.  
  148.     // Check to see if player is attacking
  149.     if(( ME == PLAYER) && (MY._FIREMODE != 0))
  150.     {
  151.         // if you have more than one attacking animation, here's where you would test for it...
  152.         // calculate a percentage out of the animation time
  153. //opt.    temp2 = 4*INT(((-MY._ADVANIM_TICK)&MASK_ANIM_ATTACK_TICKS)>>12);// anim_attack_ticks
  154.         temp2 = INT(((-MY._ADVANIM_TICK)&MASK_ANIM_ATTACK_TICKS)>>10);// anim_attack_ticks
  155.         temp =  100 * MY._ANIMDIST / temp2;
  156.         // set the frame from the percentage
  157.         // -old- set_frame ME,anim_attack_str,temp;
  158.         ent_frame(anim_attack_str,temp);
  159.  
  160.         // increment _ANIMDIST by elapsed time
  161.         MY._ANIMDIST += TIME;
  162.         // check to see if we finished the attack animation
  163.         if(MY._ANIMDIST > temp2)
  164.         {
  165.             MY._ANIMDIST = 0; // reset animation distance
  166.             MY._FIREMODE = 0;    // reset firemode
  167.         }
  168.         return;
  169.     }      //==
  170.     else // not firing
  171.     {
  172.         /////////////////////////////////////////////////////////////////////
  173.         // Animations that can take place standing still (jumping, ducking, etc.)
  174.         /////////////////////////////////////////////////////////////////////
  175.        // the jumping animation
  176.         if(MY._MOVEMODE == _MODE_JUMPING)
  177.         {
  178. //opt.             temp2 = 4*INT(((-MY._ADVANIM_TICK)&MASK_ANIM_JUMP_TICKS)>>6);// anim_jump_ticks
  179.              temp2 = INT(((-MY._ADVANIM_TICK)&MASK_ANIM_JUMP_TICKS)>>4);// anim_jump_ticks
  180.             // calculate a percentage out of the animation time
  181.             temp =  100 * MY._ANIMDIST / temp2;
  182.             // set the frame from the percentage
  183.             // -old- set_frame ME,anim_jump_str,temp;
  184.             ent_frame(anim_jump_str,temp);
  185.             // increment _ANIMDIST by elapsed time
  186.             MY._ANIMDIST += TIME;
  187.             // check to see if we finished jump animation
  188.             if(MY._ANIMDIST > temp2)
  189.             {
  190.                 MY._ANIMDIST = 0;
  191.                 MY._MOVEMODE = _MODE_WALKING;
  192.             }
  193.             return;
  194.         }
  195.  
  196.        // the ducking animation
  197.         if(MY._MOVEMODE == _MODE_DUCKING)
  198.         {
  199.               temp2 = (frc(-MY._ADVANIM_DIST)<<10);// walk_or_run
  200.            // you can only duck at walking speeds or below.
  201.             if(my_dist >= temp2*TIME*movement_scale)    // to fast to duck?
  202.             {
  203.                 MY._MOVEMODE = _MODE_WALKING; // catch the walking mode below this one
  204.              }
  205.             else
  206.             { // ducking
  207.                   temp2 = 4*INT(((-MY._ADVANIM_TICK)&MASK_ANIM_DUCK_TICKS));// anim_duck_ticks
  208.                 // calculate a percentage out of the animation time
  209.                 temp =  100 * MY._ANIMDIST / temp2;
  210.                 // set the frame from the percentage
  211.                 // -old - set_frame ME,anim_duck_str,temp;
  212.                 ent_frame(anim_duck_str,temp);
  213.                 // increment _ANIMDIST by elapsed time
  214.                 MY._ANIMDIST += TIME;
  215.                 // check to see if we finished ducking
  216.                 if(MY._ANIMDIST > temp2)
  217.                 {
  218.                     MY._ANIMDIST = 0;
  219.                     MY._MOVEMODE = _MODE_CRAWLING;
  220.                 }
  221.                 return;
  222.             }
  223.         }
  224.  
  225.         // the crawling animation
  226.         if(MY._MOVEMODE == _MODE_CRAWLING)
  227.         {
  228.               temp2 = (frc(-MY._ADVANIM_DIST)<<10);// walk_or_run
  229.             // you can only crawl at walking speeds or below.
  230.             if(my_dist >= temp2*TIME*movement_scale)    // to fast to crawl?
  231.             {
  232.                 MY._MOVEMODE = _MODE_WALKING; // catch the walking mode below this one
  233.              }
  234.             else
  235.             { // crawling
  236. //opt.                  temp2 = 0.25*INT(((-MY._ADVANIM_DIST)&MASK_ANIM_CRAWL_DIST)>>5);// anim_crawl_dist
  237.                   temp2 = (((-MY._ADVANIM_DIST)&MASK_ANIM_CRAWL_DIST)>>7);// anim_crawl_dist
  238.  
  239.                  // set the distance covered, in percent of the model width
  240.                 covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  241.                  // calculate the real cycle distance from the model size
  242.                 while(covered_dist > temp2)
  243.                 {
  244.                     covered_dist -= temp2;
  245.                 }
  246.  
  247.                 if(force.X < 0)    // moving backwards?
  248.                 {
  249.                     temp = 100 - temp;
  250.                 }
  251.                 temp = 100 * covered_dist / temp2;
  252.                 //-old- set_cycle ME,anim_crawl_str,temp;
  253.                 ent_cycle(anim_crawl_str,temp);
  254.  
  255.                 MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  256.                 return;
  257.             }
  258.  
  259.         }
  260.  
  261.         // the swimming animation
  262.         if(MY._MOVEMODE == _MODE_SWIMMING)
  263.         {
  264. //opt.                  temp2 = 0.25*INT(((-MY._ADVANIM_DIST)&MASK_ANIM_SWIM_DIST));// anim_swim_dist
  265.                   temp2 = 0.25*(((-MY._ADVANIM_DIST)&MASK_ANIM_SWIM_DIST));// anim_swim_dist
  266.  
  267.              // set the distance covered, in percent of the model width
  268.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  269.              // calculate the real cycle distance from the model size
  270.             while(covered_dist > temp2)
  271.             {
  272.                 covered_dist -= temp2;
  273.             }
  274.  
  275.             if(force.X < 0)    // moving backwards?
  276.             {
  277.                 temp = 100 - temp;
  278.             }
  279.             temp = 100 * covered_dist / temp2;
  280.             // -old- set_cycle ME,anim_swim_str,temp;
  281.             ent_cycle(anim_swim_str,temp);
  282.  
  283.             MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  284.             return;
  285.         }
  286.  
  287.  
  288.         // the wading animation  (NOTE! uses same distance as crawling)
  289.         if(MY._MOVEMODE == _MODE_WADING)
  290.         {
  291. //opt.                  temp2 = 0.25*INT(((-MY._ADVANIM_DIST)&MASK_ANIM_CRAWL_DIST)>>5);// anim_crawl_dist == anim_crawl_dist
  292.                   temp2 = (((-MY._ADVANIM_DIST)&MASK_ANIM_CRAWL_DIST)>>7);// anim_crawl_dist == anim_crawl_dist
  293.  
  294.              // set the distance covered, in percent of the model width
  295.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  296.              // calculate the real cycle distance from the model size
  297.             while(covered_dist > temp2)
  298.             {
  299.                 covered_dist -= temp2;
  300.             }
  301.  
  302.             if(force.X < 0)    // moving backwards?
  303.             {
  304.                 temp = 100 - temp;
  305.             }
  306.  
  307.             temp = 100 * covered_dist / temp2;
  308.             // -old- set_cycle ME,anim_wade_str,temp;
  309.             ent_cycle(anim_wade_str,temp);
  310.  
  311.             MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  312.             return;
  313.         }
  314.  
  315.         // the standing still animation
  316.         // NOTE: the must be *before* _MODE_WALKING but after any other mode
  317.         //      that can animate while the player is not moving (swimming,
  318.         //          ducking, jumping, etc.)
  319.         if((my_dist < 0.01) || (MY._MOVEMODE == _MODE_STILL))
  320.         {
  321. //opt.             temp2 = 4*((FRC(-MY._ADVANIM_TICK))<<10);// anim_stand_ticks
  322.              temp2 = ((FRC(-MY._ADVANIM_TICK))<<12);// anim_stand_ticks
  323.  
  324.              MY._ANIMDIST += TIME;
  325.             // wrap animation time to a value between zero and anim_stand_ticks
  326.             if(MY._ANIMDIST > temp2)
  327.             {
  328.                 MY._ANIMDIST -= temp2;
  329.             }
  330.             // calculate a percentage out of the animation time
  331.             temp =  100 * MY._ANIMDIST / temp2;
  332.             // set the frame from the percentage
  333.             // -old- set_cycle ME,anim_stand_str,temp;
  334.             ent_cycle(anim_stand_str,temp);
  335.  
  336.             return;
  337.          }
  338.  
  339.  
  340.         // walking animation
  341.         if(MY._MOVEMODE == _MODE_WALKING)
  342.         {
  343.             // set the distance covered, in percent of the model width
  344.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  345.  
  346.               temp2 = (frc(-MY._ADVANIM_DIST)<<10);// walk_or_run
  347.             // decide whether to play the walk or run animation
  348.             if(my_dist < temp2*TIME*movement_scale)    // Walking
  349.             {
  350. //opt.                  anim_dist = 0.25*INT(((-MY._ADVANIM_DIST)&MASK_ANIM_WALK_DIST)>>10);// anim_walk_dist
  351.                   anim_dist = (((-MY._ADVANIM_DIST)&MASK_ANIM_WALK_DIST)>>12);// anim_walk_dist
  352.                 anim_str = anim_walk_str;
  353.             }
  354.             else
  355.             { // running
  356. //opt.                  anim_dist = 0.25*INT(((-MY._ADVANIM_DIST)&MASK_ANIM_RUN_DIST)>>15);// anim_run_dist
  357.                   anim_dist = (((-MY._ADVANIM_DIST)&MASK_ANIM_RUN_DIST)>>17);// anim_run_dist
  358.                 anim_str = anim_run_str;
  359.             }
  360.  
  361.             // calculate the real cycle distance from the model size
  362.             if(covered_dist > anim_dist)
  363.             {
  364.                 covered_dist -= anim_dist;
  365.             }
  366.  
  367.  
  368.             temp = 100 * covered_dist / anim_dist;
  369.             if(force.X < 0)    // moving backwards?
  370.             {
  371.                 temp = 100 - temp;
  372.             }
  373.  
  374.             ent_cycle(anim_str,temp);
  375.  
  376.             if (covered_dist < MY._WALKDIST)
  377.             {
  378.                 _play_walksound();    // sound for right foot
  379.             }
  380.             if ((covered_dist > anim_dist*0.5) && (MY._WALKDIST < anim_dist*0.5))
  381.             {
  382.                 _play_walksound();    // sound for left foot
  383.             }
  384.             MY._WALKDIST = covered_dist;
  385.             return;
  386.         }
  387.         return;
  388.         // END OF ADVANCED STYLE ANIMATIONS (frame names)
  389.     }
  390. } // END actor_adv_anim()
  391.  
  392.  
  393. /////////////////////////////////////////////////////////////////////////
  394. // Desc: Main action to animate a walking actor, depending on dist
  395. //          covered (my_dist)
  396. //
  397. function actor_anim()
  398. {
  399.     // check for *ADVANCED ANIMATION* (frame names and entity tick/dist values)
  400.     if(int(MY._WALKFRAMES) < 0) { actor_adv_anim(); return; }
  401.  
  402.     // decide whether it's a frame number (old) or frame name (new) animation
  403.     if(frc(MY._WALKFRAMES) > 0) { actor_anim_old_style_anim(); return; }
  404.  
  405.  
  406.     // START NEW STYLE ANIMATIONS (frame names)
  407.  
  408.     // Check to see if player is attacking
  409.     if(( ME == PLAYER) && (MY._FIREMODE != 0))
  410.     {
  411.         // if you have more than one attacking animation, here's where you would test for it...
  412.         // calculate a percentage out of the animation time
  413.         temp =  100 * MY._ANIMDIST / anim_attack_ticks;
  414.         // set the frame from the percentage
  415.         // -old- set_frame ME,anim_attack_str,temp;
  416.         ent_frame(anim_attack_str,temp);
  417.  
  418.         // increment _ANIMDIST by elapsed time
  419.         MY._ANIMDIST += TIME;
  420.         // check to see if we finished the attack animation
  421.         if(MY._ANIMDIST > anim_attack_ticks)
  422.         {
  423.             MY._ANIMDIST = 0; // reset animation distance
  424.             MY._FIREMODE = 0;    // reset firemode
  425.         }
  426.         return;
  427.     }
  428.     else // not firing
  429.     {
  430.         /////////////////////////////////////////////////////////////////////
  431.         // Animations that can take place standing still (jumping, ducking, etc.)
  432.         /////////////////////////////////////////////////////////////////////
  433.        // the jumping animation
  434.         if(MY._MOVEMODE == _MODE_JUMPING)
  435.         {
  436.             // calculate a percentage out of the animation time
  437.             temp =  100 * MY._ANIMDIST / anim_jump_ticks;
  438.             // set the frame from the percentage
  439.             // -old- set_frame ME,anim_jump_str,temp;
  440.             ent_frame(anim_jump_str,temp);
  441.             // increment _ANIMDIST by elapsed time
  442.             MY._ANIMDIST += TIME;
  443.             // check to see if we finished jump animation
  444.             if(MY._ANIMDIST > anim_jump_ticks)
  445.             {
  446.                 MY._ANIMDIST = 0;
  447.                 MY._MOVEMODE = _MODE_WALKING;
  448.             }
  449.             return;
  450.         }
  451.  
  452.        // the ducking animation
  453.         if(MY._MOVEMODE == _MODE_DUCKING)
  454.         {
  455.            // you can only duck at walking speeds or below.
  456.             if(my_dist >= walk_or_run*TIME*movement_scale)    // to fast to duck?
  457.             {
  458.                 MY._MOVEMODE = _MODE_WALKING; // catch the walking mode below this one
  459.              }
  460.             else
  461.             { // ducking
  462.                 // calculate a percentage out of the animation time
  463.                 temp =  100 * MY._ANIMDIST / anim_duck_ticks;
  464.                 // set the frame from the percentage
  465.                 // -old - set_frame ME,anim_duck_str,temp;
  466.                 ent_frame(anim_duck_str,temp);
  467.                 // increment _ANIMDIST by elapsed time
  468.                 MY._ANIMDIST += TIME;
  469.                 // check to see if we finished ducking
  470.                 if(MY._ANIMDIST > anim_duck_ticks)
  471.                 {
  472.                     MY._ANIMDIST = 0;
  473.                     MY._MOVEMODE = _MODE_CRAWLING;
  474.                 }
  475.                 return;
  476.             }
  477.         }
  478.  
  479.         // the crawling animation
  480.         if(MY._MOVEMODE == _MODE_CRAWLING)
  481.         {
  482.  
  483.             // you can only crawl at walking speeds or below.
  484.             if(my_dist >= walk_or_run*TIME*movement_scale)    // to fast to crawl?
  485.             {
  486.                 MY._MOVEMODE = _MODE_WALKING; // catch the walking mode below this one
  487.              }
  488.             else
  489.             { // crawling
  490.                  // set the distance covered, in percent of the model width
  491.                 covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  492.                  // calculate the real cycle distance from the model size
  493.                 while(covered_dist > anim_crawl_dist)
  494.                 {
  495.                     covered_dist -= anim_crawl_dist;
  496.                 }
  497.  
  498.                 if(force.X < 0)    // moving backwards?
  499.                 {
  500.                     temp = 100 - temp;
  501.                 }
  502.                 temp = 100 * covered_dist / anim_crawl_dist;
  503.                 //-old- set_cycle ME,anim_crawl_str,temp;
  504.                 ent_cycle(anim_crawl_str,temp);
  505.  
  506.                 MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  507.                 return;
  508.             }
  509.  
  510.         }
  511.  
  512.         // the swimming animation
  513.         if(MY._MOVEMODE == _MODE_SWIMMING)
  514.         {
  515.              // set the distance covered, in percent of the model width
  516.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  517.              // calculate the real cycle distance from the model size
  518.             while(covered_dist > anim_swim_dist)
  519.             {
  520.                 covered_dist -= anim_swim_dist;
  521.             }
  522.  
  523.             if(force.X < 0)    // moving backwards?
  524.             {
  525.                 temp = 100 - temp;
  526.             }
  527.             temp = 100 * covered_dist / anim_swim_dist;
  528.             // -old- set_cycle ME,anim_swim_str,temp;
  529.             ent_cycle(anim_swim_str,temp);
  530.  
  531.             MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  532.             return;
  533.         }
  534.  
  535.  
  536.         // the wading animation
  537.         if(MY._MOVEMODE == _MODE_WADING)
  538.         {
  539.              // set the distance covered, in percent of the model width
  540.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  541.              // calculate the real cycle distance from the model size
  542.             while(covered_dist > anim_wade_dist)
  543.             {
  544.                 covered_dist -= anim_wade_dist;
  545.             }
  546.  
  547.             if(force.X < 0)    // moving backwards?
  548.             {
  549.                 temp = 100 - temp;
  550.             }
  551.  
  552.             temp = 100 * covered_dist / anim_wade_dist;
  553.             // -old- set_cycle ME,anim_wade_str,temp;
  554.             ent_cycle(anim_wade_str,temp);
  555.  
  556.             MY._WALKDIST = covered_dist;     // save for next 'frame' of animation
  557.             return;
  558.         }
  559.  
  560.         // the standing still animation
  561.         // NOTE: the must be *before* _MODE_WALKING but after any other mode
  562.         //      that can animate while the player is not moving (swimming,
  563.         //          ducking, jumping, etc.)
  564.         if((my_dist < 0.01) || (MY._MOVEMODE == _MODE_STILL))
  565.         {
  566.              MY._ANIMDIST += TIME;
  567.             // wrap animation time to a value between zero and anim_stand_ticks
  568.             if(MY._ANIMDIST > anim_stand_ticks)
  569.             {
  570.                 MY._ANIMDIST -= anim_stand_ticks;
  571.             }
  572.             // calculate a percentage out of the animation time
  573.             temp =  100 * MY._ANIMDIST / anim_stand_ticks;
  574.             // set the frame from the percentage
  575.             // -old- set_cycle ME,anim_stand_str,temp;
  576.             ent_cycle(anim_stand_str,temp);
  577.  
  578.             return;
  579.          }
  580.  
  581.  
  582.         // walking animation
  583.         if(MY._MOVEMODE == _MODE_WALKING)
  584.         {
  585.             // set the distance covered, in percent of the model width
  586.             covered_dist = MY._WALKDIST + my_dist / (MY.MAX_X-MY.MIN_X);
  587.  
  588.             // decide whether to play the walk or run animation
  589.             if(my_dist < walk_or_run*TIME*movement_scale)    // Walking
  590.             {
  591.                 anim_dist = anim_walk_dist;
  592.                 anim_str = anim_walk_str;
  593.             }
  594.             else
  595.             { // running
  596.                 anim_dist = anim_run_dist;
  597.                 anim_str = anim_run_str;
  598.             }
  599.  
  600.             // calculate the real cycle distance from the model size
  601.             if(covered_dist > anim_dist)
  602.             {
  603.                 covered_dist -= anim_dist;
  604.             }
  605.  
  606.  
  607.             temp = 100 * covered_dist / anim_dist;
  608.             if(force.X < 0)    // moving backwards?
  609.             {
  610.                 temp = 100 - temp;
  611.             }
  612.  
  613.             ent_cycle(anim_str,temp);
  614.  
  615.             if (covered_dist < MY._WALKDIST)
  616.             {
  617.                 _play_walksound();    // sound for right foot
  618.             }
  619.             if ((covered_dist > anim_dist*0.5) && (MY._WALKDIST < anim_dist*0.5))
  620.             {
  621.                 _play_walksound();    // sound for left foot
  622.             }
  623.             MY._WALKDIST = covered_dist;
  624.             return;
  625.         }
  626.         return;
  627.         // END OF NEW STYLE ANIMATIONS (frame names)
  628.     }
  629.  
  630.     /* ??? No longer needed ???
  631.     if((MY._MOVEMODE == _MODE_STILL) || (my_dist < 0.01))
  632.     {
  633.         // if the entity has a standing animation, instead of just one frame,
  634.         // place it here. Otherwise...
  635.         MY.FRAME = 1;    // standing
  636.         return;
  637.     }
  638.     */
  639. }
  640.  
  641.  
  642. /////////////////////////////////////////////////////////////////////////
  643. // Desc: Handle transitions between states
  644. //
  645. // *** WORK IN PROGRESS ***
  646. var    anim_trans_cycle = 0;  // "local" var
  647. function    actor_anim_transition(str_anim_target)
  648. {
  649. //    ME = player;
  650. //    wait(1);     // let calling function finish one loop
  651.  
  652.     MY._ANIMDIST = 0;
  653.  
  654.     // set the frame and next_frame values
  655.     temp = MY.frame;
  656. //--    ent_frame("swim",0);
  657.     ent_frame(str_anim_target,0);
  658.     MY.next_frame = MY.frame;
  659.     MY.frame = temp;
  660.  
  661.     anim_trans_cycle = MY._MOVEMODE;
  662.     MY._MOVEMODE = _MODE_TRANSITION;
  663.  
  664.     // do .25 sec transition (4 ticks)
  665.     while(MY._ANIMDIST < 4)
  666.     {
  667.         MY.frame = int(MY.frame) + (MY._ANIMDIST / 4.0);
  668. //tst_value_3 = MY.frame * 10;
  669.  
  670.         MY._ANIMDIST += TIME;
  671. //tst_value_4 = MY._ANIMDIST;
  672.         wait(1);
  673.     }
  674.     MY._ANIMDIST = 0;
  675.      MY._MOVEMODE = anim_trans_cycle;
  676. }
  677.  
  678.  
  679. /////////////////////////////////////////////////////////////////////////
  680. // Desc: Handle 'old' A4 style of animation
  681. //            Called from "actor_anim()"
  682. //
  683. function actor_anim_old_style_anim()
  684. {
  685.     if(MY._MOVEMODE == _MODE_WALKING)
  686.     {
  687.         // decide whether to play the walk or run animation
  688.         if((MY._RUNFRAMES <= 0) || (my_dist < walk_or_run*TIME*movement_scale))    // Walking
  689.         {
  690.             if(MY.FRAME < 2) { MY.FRAME = 2; }
  691.  
  692.             MY.FRAME += MY._WALKDIST*my_dist;
  693.  
  694.             // this is one of the expert exceptions where you can use WHILE without WAIT!
  695.             while(MY.FRAME >= 2 + MY._WALKFRAMES)
  696.             {
  697.                 // sound for right foot
  698.                 if(MY.__SOUND == ON) { _play_walksound(); MY.__SOUND = OFF; }
  699.                 // cycle the animation
  700.                 MY.FRAME -= MY._WALKFRAMES;
  701.             }
  702.  
  703.             if(MY.FRAME > 1 + MY._WALKFRAMES*0.5) {
  704.                 // sound for left foot
  705.                 if(MY.__SOUND == OFF) { _play_walksound(); MY.__SOUND = ON; }
  706.             }
  707.  
  708.             if(MY.FRAME > 1 + MY._WALKFRAMES)
  709.             {
  710.                 MY.NEXT_FRAME = 2;    // inbetween to the first walking frame
  711.             }
  712.             else
  713.             {
  714.                 MY.NEXT_FRAME = 0;    // inbetween to the real next frame
  715.             }
  716.             return;
  717.         }
  718.         else
  719.         {    // Running
  720.             if(MY.FRAME < 2 + MY._WALKFRAMES) { MY.FRAME = 2 + MY._WALKFRAMES; }
  721.  
  722.             MY.FRAME += MY._RUNDIST*my_dist;
  723.  
  724.             while(MY.FRAME >= 2 + MY._WALKFRAMES + MY._RUNFRAMES)
  725.             {
  726.                 if(MY.__SOUND == ON) { _play_walksound(); MY.__SOUND = OFF; }
  727.                 MY.FRAME -= MY._RUNFRAMES;
  728.             }
  729.  
  730.             if(MY.FRAME > 1 + MY._WALKFRAMES + MY._RUNFRAMES*0.5)
  731.             {
  732.                 if(MY.__SOUND == OFF) { _play_walksound(); MY.__SOUND = ON; }
  733.             }
  734.  
  735.             if(MY.FRAME > 1 + MY._WALKFRAMES + MY._RUNFRAMES)
  736.             {
  737.                 MY.NEXT_FRAME = 2 + MY._WALKFRAMES;
  738.             }
  739.             else
  740.             {
  741.                 MY.NEXT_FRAME = 0;
  742.             }
  743.  
  744.             return;
  745.         }
  746.     }
  747. }
  748.  
  749.  
  750. /////////////////////////////////////////////////////////////////////////
  751. // Desc: create a shadow below the entity
  752. ACTION drop_shadow
  753. {
  754. IFDEF CAPS_FLARE;
  755.     if(VIDEO_DEPTH >= 16)
  756.     {
  757.         create(SHADOWSPRITE,MY.POS,move_shadow);
  758.     }
  759.     else
  760.     {
  761.         create(SHADOWFLAT,MY.POS,move_shadow);
  762.     }
  763. IFELSE;
  764.     create(SHADOWFLAT,MY.POS,move_shadow);
  765. ENDIF;
  766. }
  767.  
  768.  
  769.  
  770. /////////////////////////////////////////////////////////////////////////
  771. //    Desc: function used to move shadow
  772. //
  773. function move_shadow()
  774. {
  775.     MY.flare = ON;
  776.     MY.transparent = ON; //inverse alpha
  777.     MY.passable = ON;
  778.     MY.oriented = ON;
  779.     MY.ambient = -100; // shadow should be totally black
  780.     MY.unlit = ON;         //(plus UNLIT flag in version 4.20)
  781.  
  782.     // scale the shadow so that it matches its master's (YOU) size
  783.     MY.scale_x = (YOU.MAX_X - YOU.MIN_X)/(MY.MAX_X - MY.MIN_X);
  784.     MY.scale_y = MY.scale_x * 0.8;
  785.     MY.scale_z = 1.0;
  786.     while(YOU != NULL)
  787.     {
  788.         if ((YOU.invisible == ON)
  789.         || (YOU._MOVEMODE == _MODE_SWIMMING)
  790.         || (YOU._MOVEMODE == _MODE_WADING))
  791.         {
  792.             MY.invisible = ON;
  793.         }
  794.         else
  795.         {
  796.             MY.invisible = OFF;
  797.               temp_ent = YOU;
  798.  
  799.  
  800.             //-old-sonar temp_ent,500; // get height above the floor
  801.             trace_mode = IGNORE_PASSENTS
  802.                   + IGNORE_ME
  803.                   + IGNORE_YOU
  804.                   + IGNORE_MODELS;
  805.             vec_set(vecFrom,YOU.X);
  806.             vec_set(vecTo,vecFrom);
  807.             vecTo.Z -= 500;
  808.             result = trace(vecFrom,vecTo);
  809.  
  810.             YOU = temp_ent; // YOU (the entity itself) is changed by SONAR
  811.  
  812.             if(result > 0)
  813.             {
  814.                 // place shadow 2 quants above the floor
  815.                 MY.z = YOU.z - RESULT + 2; //YOUR.min_z*/ + 2 - RESULT;
  816.                 MY.x = YOU.x;
  817.                 MY.y = YOU.y;
  818. //--                  MY.pan = YOU.pan;
  819.  
  820.                 // adapt shadow orientation to floor slope
  821.                 if ((NORMAL.x != 0) || (NORMAL.y != 0))
  822.                 { // we're on a slope
  823.                     // conform shadow to slope
  824.                     MY.PAN = 0;
  825.                     MY.tilt = - asin(NORMAL.x);
  826.                     MY.roll = - asin(NORMAL.y);
  827.                     temp.pan = YOU.PAN;
  828.                     temp.tilt = 90;
  829.                     temp.roll = 0;
  830.                     rotate(my,temp,nullvector);
  831.                  }
  832.                 else
  833.                 {
  834.                     MY.pan = YOU.pan;
  835.                     MY.tilt = 90; // set it flat onto the floor
  836.                     MY.roll = 0;
  837.                 }
  838.             }
  839.             else
  840.             {
  841.                 MY.INVISIBLE = ON;
  842.             }
  843.         }
  844.         wait(1);
  845.     } // end while(YOU != NULL)
  846.     remove(ME);
  847. }
  848.  
  849.  
  850. /////////////////////////////////////////////////////////////////////////
  851. // Desc: attaches an entity that has the same origin and the same frame cycles
  852. //
  853. function attach_entity()
  854. {
  855.    my.passable = on;
  856.    while(you)    // prevent empty synoym error if parent entity was removed
  857.    {
  858.        if(your.shadow == on) { my.shadow = on; }
  859.        if(you == player && person_3rd == 0)
  860.         {
  861.           my.invisible = on;
  862.        }
  863.         else
  864.         {
  865.           my.invisible = off;
  866.        }
  867.  
  868.        vec_set(my.x,you.x);
  869.        vec_set(my.pan,you.pan);
  870.        my.frame = you.frame;
  871.        my.next_frame = you.next_frame;
  872.        wait(1);
  873.    }
  874.     remove(my);
  875. }
  876.  
  877.  
  878. ///////////////////////////////////////////////////////////////////////
  879. // Desc: Shakes the player, used for hits and death
  880. function player_shake()
  881. {
  882.     if(random(1) > 0.5)
  883.     {
  884.         MY.ROLL += 8;
  885.         MY.TILT += 8;
  886.         waitt(2);
  887.         MY.TILT -= 5;
  888.         waitt(2);
  889.         MY.ROLL -= 8;
  890.         MY.TILT -= 3;
  891.     }
  892.     else
  893.     {
  894.         MY.ROLL -= 8;
  895.         MY.TILT += 8;
  896.         waitt(2);
  897.         MY.TILT -= 5;
  898.         waitt(2);
  899.         MY.ROLL += 8;
  900.         MY.TILT -= 3;
  901.     }
  902. }